package com.core.zyyz.amc.modules.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.ValueSetValue;
import com.core.zyyz.pcmc.service.ValueSetValueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.zyyz.amc.modules.domain.AmcCusContactD;
import com.core.zyyz.amc.modules.service.AmcCusContactDService;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 客户联系人Controller
 *
 * @author lfs
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/amc/cuscontact")
public class AmcCusContactDController extends BaseController
{
    @Autowired
    private AmcCusContactDService amcCusContactDService;
    @Autowired
    private ValueSetValueService valueSetValueService;

    /**
     * 查询客户联系人列表
     */
    @PreAuthorize("@ss.hasPermi('amc:cuscontact:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmcCusContactD amcCusContactD)
    {
        startPage();
        List<AmcCusContactD> list = amcCusContactDService.selectAmcCusContactDList(amcCusContactD);
        return getDataTable(list);
    }

    /**
     * 获取客户联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('amc:cuscontact:query')")
    @GetMapping(value = "/{contactId}")
    public AjaxResult getInfo(@PathVariable("contactId") String contactId)
    {
        return success(amcCusContactDService.selectAmcCusContactDByContactId(contactId));
    }

    /**
     * 根据页面的集值定义去查询具体的集值数据（页面中下拉框的值）
     *
     * @return
     */
    @GetMapping("/valueSetCodeList")
    public AjaxResult valueSetCodeList(){
        Map<String, Object> map = new HashMap<String, Object>();
        //contact_type 联系人类型;contact_id_types 联系人证件种类;sex 性别;contact_customer_type 关联客户类别;
        String[] str ={"contact_type", "contact_id_types", "sex", "contact_customer_type"};
        ValueSetValue value = new ValueSetValue();
        for(int i=0;i<str.length;i++){
            value.setValueSetCode(str[i]);
            List<ValueSetValue> valueSetValues = valueSetValueService.selectValueSetValueList(value);
            map.put(str[i], valueSetValues);
        }
        return success(map);
    }

    /**
     * 新增客户联系人
     */
    @PreAuthorize("@ss.hasPermi('amc:cuscontact:add')")
    @Log(title = "客户联系人", businessType = BusinessType.INSERT)
    @PostMapping("/insertCusContact")
    public AjaxResult add(@RequestBody AmcCusContactD amcCusContactD) {
        return toAjax(amcCusContactDService.insertAmcCusContactD(amcCusContactD));
    }

    /**
     * 修改客户联系人
     */
    @PreAuthorize("@ss.hasPermi('amc:cuscontact:edit')")
    @Log(title = "客户联系人", businessType = BusinessType.UPDATE)
    @PostMapping("/updateCusContact")
    public AjaxResult edit(@RequestBody AmcCusContactD amcCusContactD)
    {
        return toAjax(amcCusContactDService.updateAmcCusContactD(amcCusContactD));
    }

    /**
     * 删除客户联系人
     */
    @PreAuthorize("@ss.hasPermi('amc:cuscontact:remove')")
    @Log(title = "客户联系人", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contactIds}")
    public AjaxResult remove(@PathVariable String[] contactIds)
    {
        return toAjax(amcCusContactDService.deleteAmcCusContactDByContactIds(contactIds));
    }
}
